﻿using Keyer.DataBase.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Text;

namespace Keyer.DataBase.Mapping.Sqlite
{
    public class PersonMap : EntityTypeConfiguration<sys_person>
    {
        public PersonMap()
        {
            // 表名
            this.ToTable("Person");

            // 主键
            this.HasKey(t => t.id);

            // 属性设置
            this.Property(t => t.id)
                .HasColumnName("personId")
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
            this.Property(t => t.name)
                .HasColumnName("name")
                .HasMaxLength(20)
                .IsRequired();
            this.Property(t => t.qq)
                .HasColumnName("qq")
                .HasMaxLength(20);
            this.Property(t => t.wx)
                .HasColumnName("wx")
                .HasMaxLength(20);
            this.Property(t => t.sex)
                 .HasColumnName("sex")
                 .HasMaxLength(8)
                 .IsRequired();
            this.Property(t => t.organId)
                .HasColumnName("organId");

            //Base属性设置            
            this.Property(t => t.createUser)
                .HasColumnName("createUser")
                .HasMaxLength(20);
            this.Property(t => t.createTime)
                 .HasColumnName("createTime");
            this.Property(t => t.rowVersion)
                .HasColumnName("rowVersion")
                .IsRowVersion();

            // 关联设置
            this.HasRequired(t => t.organ)
                .WithMany(t => t.persons)
                .HasForeignKey(t => t.organId)
                .WillCascadeOnDelete(false);
        }
    }
}
